<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>vue.draggable两列或多列之间相互拖动例子</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
    <script src="http://www.itxst.com/package/vue/vue.min.js"></script>
    <script src="http://www.itxst.com/package/sortable/Sortable.min.js"></script>
    <script src="http://www.itxst.com/package/vuedraggable/vuedraggable.umd.min.js"></script>
    <style>
        /*定义要拖拽元素的样式*/
        .ghostClass {
            background-color: blue !important;
        }

        .chosenClass {
            background-color: red !important;
            opacity: 1 !important;
        }

        .dragClass {
            background-color: blueviolet !important;
            opacity: 1 !important;
            box-shadow: none !important;
            outline: none !important;
            background-image: none !important;
        }

        .itxst {
            margin: 10px;
        }

        .title {
            padding: 6px 12px;
        }

        .col {
            width: 40%;
            flex: 1;
            padding: 10px;
            border: solid 1px #eee;
            border-radius: 5px;
            float: left;
        }

         .col + .col {
                margin-left: 10px;
            }
        .item {
            padding: 6px 12px;
            margin: 0px 10px 0px 10px;
            border: solid 1px #eee;
            background-color: #f1f1f1;
        }

            .item:hover {
                background-color: #fdfdfd;
                cursor: move;
            }

            .item + .item {
                border-top: none;
                margin-top: 6px;
            }
            .mover {
          background-color: #fdfdfd;
          cursor: move;
          padding:3px 6px;
      }
    </style>
</head>
<body style="padding:10px;">
    <div id="app">
        <!--使用draggable组件-->
        <div class="itxst">
            <div class="col">
                <div class="title">标签</div>
                <draggable handle=".mover" v-model="arr1" group="site" animation="300" dragClass="dragClass" ghostClass="ghostClass" chosenClass="chosenClass" @start="onStart" @end="onEnd">
                    <transition-group style="display:inline-block;min-height:300px;width:100%;background:#ccc;">
                       <div class="item" v-for="item in arr1" :key="item.id">{{item.name}}<span class="mover">+</span></div>
                    </transition-group>
                </draggable>
            </div>
            <!-- //两列组件设置相同的group名就可以相互拖拽了 -->
            <div class="col">
                <div class="title">标签池</div>
                <draggable v-model="arr2" filter=".forbid"  group="site" animation="300"  dragClass="dragClass" ghostClass="ghostClass" chosenClass="chosenClass" @start="onStart" @end="onEnd">
                    <!-- dragClass="dragClass" ghostClass="ghostClass" chosenClass="chosenClass" @start="onStart" @end="onEnd" -->
                    <transition-group style="display:inline-block;min-height:300px;width:100%;background:#ccc;">
                        <div class="item forbid" v-for="item in arr2" :key="item.id">{{item.name}}</div>
                    </transition-group>
                </draggable>
            </div>
        </div>
      
    </div>
    <script>
        // debugger;
        Vue.component('vuedraggable', window.vuedraggable.name)
        var app = new Vue({
            el: '#app',
            components: {
                vuedraggable,
            },
            data() {
                return {
                    drag: false,
                    arr1: [
                        { id: 1, name: '标签1' },
                        { id: 2, name: '标签2' },
                        { id: 3, name: '标签3' },
                        { id: 4, name: '标签4' }
                    ],
                    arr2: [
                        // { id: 1, name: 'www.google.com' },
                        // { id: 2, name: 'www.msn.com' },
                        // { id: 3, name: 'www.ebay.com' },
                        // { id: 4, name: 'www.yahoo.com' }
                    ]
                };
            },
            methods: {
                onStart() {
                    this.drag = true;
                },
                onEnd() {
                    this.drag = false;
                },

            }
        });
    </script>
</body>
</html>